import { createApp } from 'vue'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import App from './App.vue'
import '@/assets/vant-custom.css'
import 'vant/lib/index.css'
import '@/assets/reset.css'
import router from './router'
import Vconsole from 'vconsole'
import { initSharkConfig, getQueryString } from '@/utils'

const is_Prod = import.meta.env.PROD && /timedg/.test(window.location.href)
const isDebug = getQueryString('showVcon') === '1'
if (import.meta.env.DEV || isDebug) {
  new Vconsole()
}
if (is_Prod) initSharkConfig()
const pinia = createPinia()
const app = createApp(App)

pinia.use(piniaPluginPersistedstate)
app.use(router)
app.use(pinia)
app.mount('#app')
// 全局监听错误
app.config.errorHandler = (err, vm, info) => {
  console.error(err)
  console.error(vm)
  console.error(info)
}

// 全局监听警告
app.config.warnHandler = (msg, vm, info) => {
  console.warn(msg)
  console.warn(vm)
  console.warn(info)
}

// 设置rem函数
function setRem() {
  const designWidth = 720 // 设计稿宽度
  const baseSize = 72 // 基础字体大小
  const scale = (window.innerWidth>720?720:window.innerWidth) / designWidth
  document.documentElement.style.fontSize = baseSize * Math.min(scale, 2) + 'px'
}

// 初始化
setRem()

// 改变窗口大小时重新设置rem
window.addEventListener('resize', setRem)
